import wepy from 'wepy'
import cateData from '../../assets/cates'
export default class catesjs extends wepy.mixin {
  data = {
    cateList:[],
    activeKey:0,
    secondCate:[]
  }

  config = {
  }

  methods = {
    // 当sidebar的选中值改变时
    sidebarChange(e){
      //e.detail 当前选中的索引值
      // 随着选中索引值的改变 改变secondcate的值
      this.secondCate = this.cateList[e.detail].children;
    }
  }
  // 获取分类数据
  async getCatesList(){
    //上线阶段
    // const {data} = await wepy.get("/categories")

    //开发阶段
    const data = cateData;

    // 下面代码不变
    console.log(data);
    if(data.status !== 200) return wepy.baseToast()
    this.cateList = data.message;
    //将分类的数组的第一项给二级分类数组
    this.secondCate = this.cateList[0].children;
    this.$apply()
  }

  onLoad(){
    this.getCatesList()
  }

  onShow(){
    this.$parent.setTabBarBadge(); 
  }
}